﻿using Hinacom.Scheduler;
using Hinacom.Scheduler.Service.Proxy;
using System.Windows.Forms;

namespace Hinacom.Scheduler.Manager
{
    public partial class JobInfoForm : Form
    {
        public JobInfoForm()
        {
            InitializeComponent();
        }
        public JobInfoForm(JobInfo jobInfo) : this()
        {
            jobInfoView.EditMode = true;
            jobInfoView.JobInfo = jobInfo;
        }

        private void btnSave_Click(object sender, System.EventArgs e)
        {
            if (!jobInfoView.ValidateInput()) return;

            var jobInfo = jobInfoView.JobInfo;
            if (jobInfo == null) return;

            if (jobInfoView.EditMode)
                new SchedulerProxy().EditJob(jobInfo);
            else
                new SchedulerProxy().CreateJob(jobInfo);

            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void btnCancel_Click(object sender, System.EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}
